	$.ajaxSetup({
		 async : false
	});
	var ip = 'http://' + document.location.host;
	
	//弹窗返回按钮
	$('.closeBtn').on('click',function() {
		location.reload();
		window.parent.document.getElementById("alert_shade").style.display="none";
		window.parent.document.getElementById("add_produce_box").style.display="none";
	});
	
	$('#type').change(function(){
		var value=$(this).children('option:selected').val();//这就是selected的值
		if(value=="年报"){
			document.getElementById("year").style.display="";
			document.getElementById("half").style.display="none";
	        document.getElementById("quarter").style.display="none";
	        document.getElementById("month").style.display="none";
	    }else if(value=="半年报"){	
	    	document.getElementById("year").style.display="";
	        document.getElementById("half").style.display="";
	        document.getElementById("quarter").style.display="none";
	        document.getElementById("month").style.display="none";
	    }else if(value=="季报"){
	    	document.getElementById("year").style.display="";
	    	document.getElementById("half").style.display="none";
	        document.getElementById("quarter").style.display="";
	        document.getElementById("month").style.display="none";
	    }else if(value=="月报"){
	    	document.getElementById("year").style.display="";
	    	document.getElementById("half").style.display="none";
	        document.getElementById("quarter").style.display="none";
	        document.getElementById("month").style.display="";
	    }else{
	    	document.getElementById("year").style.display="none";
	    	document.getElementById("half").style.display="none";
	        document.getElementById("quarter").style.display="none";
	        document.getElementById("month").style.display="none";
	    }
	})
	
	//法院ztree
	$(function() {
	    initTree();
	})

	var setting_ztree = {
	    view: {
	        showLine: true,
	        showIcon:true,
	        selectedMulti : true,
	        dblClickExpand: false,
	        addHoverDom: addHoverDom,
	        removeHoverDom: removeHoverDom
	    },check : {
	        enable : true,
	        chkStyle : "checkbox",
	        radioType : "all"
	    },
	    data: {
	        simpleData: {
	            enable: true
	        }
	    },
	    callback: {
	        //onClick: onClick_ztree,
	        /*onCheck: onClick_ztree*/
	    }
	};
	function addHoverDom(treeId, treeNode) {
	    $("#" + treeNode.tId).addClass("hover");
	};
	function removeHoverDom(treeId, treeNode) {
	    $("#" + treeNode.tId).removeClass("hover");
	};
	function filter(node) {
		var fybm = node.id;
		var fymc = node.name;
		//if((fybm.length==3&&fybm.substr(2,1)!='0'&&(fybm.substr(0,1)=='1'||fybm.substr(0,1)=='2'||fybm.substr(0,1)=='M'||fybm.substr(0,1)=='9'))||fymc.indexOf("上海金融法院")!=-1||fymc.indexOf("矿区")!=-1||fymc.indexOf("知识产权")!=-1||fymc.indexOf("铁路运输")!=-1||fymc.indexOf("人民解放军")!=-1||fymc.indexOf("海事法院")!=-1||(fybm.length==3&&fybm=='000')||(fybm.length==3&&fybm.substring(0,2)=='79')||(fybm.length==3&&fybm.substring(0,2)=='7C')||(fybm.length==3&&fybm.substring(0,2)=='8J')||(fybm.length==3&&fybm.substring(0,2)=='SG')||(fybm.length==3&&fybm.substring(0,2)=='8G')||(fybm.length==3&&fybm.substring(0,2)=='6G')||(fybm.length==3&&fybm.substring(0,2)=='L3')||(fybm.length==3&&fybm.substring(0,2)=='L5')||(fybm.length==3&&fybm.substring(0,2)=='L6')||(fybm.length==3&&fybm.substring(0,2)=='16')||(fybm.length==3&&fybm.substring(0,2)=='93')||(fybm.length==3&&fybm.substring(0,2)=='HD')){//||(fybm.length==3&&fybm.substring(2,3)!='0')||(fybm.length==3&&fybm.substring(2,1)!='0')	
		if(fymc.indexOf("全部")!=-1||fybm.length==4||fymc.indexOf("上海金融法院")!=-1||fymc.indexOf("矿区")!=-1||fymc.indexOf("知识产权")!=-1||fymc.indexOf("铁路运输")!=-1||fymc.indexOf("人民解放军")!=-1||fymc.indexOf("海事法院")!=-1||(fybm.length==3&&fybm.substring(0,2)=='79')||(fybm.length==3&&fybm.substring(0,2)=='7C')||(fybm.length==3&&fybm.substring(0,2)=='8J')||(fybm.length==3&&fybm.substring(0,2)=='SG')||(fybm.length==3&&fybm.substring(0,2)=='8G')||(fybm.length==3&&fybm.substring(0,2)=='6G')||(fybm.length==3&&fybm.substring(0,2)=='L3')||(fybm.length==3&&fybm.substring(0,2)=='L5')||(fybm.length==3&&fybm.substring(0,2)=='L6')||(fybm.length==3&&fybm.substring(0,2)=='16')||(fybm.length==3&&fybm.substring(0,2)=='93')||(fybm.length==3&&fybm.substring(0,2)=='HD')){
			return node;
		}
	} 
	var initTree = function(){
	        $.ajaxSettings.async = false;
	        $.post( "/user/tree", {}, function(response) {
	            var zNodes = response.data;
	            zTreeObj = $.fn.zTree.init($("#partTree"), setting_ztree, zNodes);
	            var nodes = zTreeObj.getNodes();
	            if (nodes.length>0) {
	                for(var i=0;i<nodes.length;i++){
	                    zTreeObj.expandNode(nodes[i], true, false, false);//默认展开第一级节点
	                }
	            }
	            var nodescheck = zTreeObj.getNodesByFilter(filter);
	            for(var i=0;i<nodescheck.length;i++){
	            	nodescheck[i].nocheck = true;
	                zTreeObj.updateNode(nodescheck[i]);
	            }
	        });
	        $.ajaxSettings.async = true;
	}
	var mapcolor = {"spzxyycolor":["#bbf0f0","#AEEEEE","#89e5e5","#57dada","#2cc8c8","#00CDCD","#219696","#008B8B","#008080","#166464","#2F4F4F"]};
	var mapchooseColor = mapcolor.spzxyycolor;
	
	//用户输入判断
	$('.saveBtn').on('click', function() {
		var type = $('#type').val();
		var zTree = $.fn.zTree.getZTreeObj("partTree");
		var nodes = zTree.getCheckedNodes();
		var year = "";
		var timeDimension = "";
		var fybm = "";
		var fymc = "";
		if(type=='年报'){
        	year = $('#year').val();
        }else if(type=='半年报'){
        	year = $('#year').val();
        	timeDimension = $('#half').val();
        }else if(type=='季报'){
        	year = $('#year').val();
        	timeDimension = $('#quarter').val();
        }else if(type=='月报'){
        	year = $('#year').val();
        	timeDimension = $('#month').val();
        }
		/*if(nodes.length==0){
			layer.tips("所属法院不能为空！", '#partTree', {time: 2000,tips: [3,"red"]});
			return false;
		}else{
			fybm = nodes[0].id;
			fymc = nodes[0].name;
		}*/
		
		if(nodes.length==0){
			layer.tips("所属法院不能为空！", '#partTree', {time: 2000,tips: [3,"red"]});
			return false;
		}else{
			for(var i=0;i<nodes.length;i++){
				if(nodes[i].id!='0'){
					generateMap(fybm,type,year,timeDimension);//生成地图
					fybm = fybm + ";" + nodes[i].id;
					fymc = fymc + ";" + nodes[i].name;
				}
			}
		}

       $.ajax({
            type: "POST",
            url: '/report/produce',
            data:{"type":type,"fybms":fybm,"fymcs":fymc,"year":year,"timeDimension":timeDimension},
            success: function(res) {
	        	if(res.code == 200){
	        		location.reload();
	        		parent.location.reload();
	        	}else{
	        		layer.alert(res.msg, {icon: 5,title: "提示"});
	        	}
	            
	        }
        });
		
		
	});
	
	
	function generateMap(fybm,type,year,timeDimension) {
		$.ajax({
			 type: 'POST',
			 url: '/report/getMapData?fybm='+fybm+'&type='+type+'&year='+year+'&timeDimension='+timeDimension,
			 async:false,
			 success: function(res) {
				 var allMapData = eval("("+res.data+")");/*将接口数据string转为json*/
				 picLoad(fybm,allMapData);
			 },
			 error: function(error) {
				 // console.log(error);
				 layer.alert(error, {icon: 5,title: "提示"});
			 }
		});
	};
	function picLoad(fybm,year,timeDimension,allMapData){
		$.ajax({
	        type : 'POST',
	        url : '/report/loadpic',
	        data : {
	        	"fybm":fybm,
	        	"year":year,
	        	"timeDimension":timeDimension,
	            "data1" :getMapStream(fybm,allMapData[0]),
				"data2" :getMapStream(fybm,allMapData[1])
	        },
	        contentType : "application/x-www-form-urlencoded",
	        success : function(data) {
	        	
	        }
	    });
	}

	function getMapStream(fybm, mapdata) {
				var dom = document.getElementById("map_show");
				var myChart = echarts.init(dom);
				myChart.clear();
				var app = {};
				option = null;
				var uploadedDataURL = 'json/' + fybm + '.geoJson';
				var data1;
				var data = [];
				var maximum = Number(mapdata.maxmin_data[0].max);
				var minimum = Number(mapdata.maxmin_data[0].min);
				var resultname;
				var resultvalue;

				for (var i = 0; i < mapdata.map_data.length; i++) {
					data1 = {};//重点
					var resultname = mapdata.map_data[i].region;

					data1.name = resultname;
					data1.value = Number(mapdata.map_data[i].result);
					data[i] = data1;
				}
				var chart;
				$.get(uploadedDataURL, function(as) {
					echarts.registerMap('FuJian', as);
					option = {
						title : {
							subtext : mapdata.title,
							x : 'center',
							subtextStyle : {
								color : "#c0c0c0",
								fontSize : 18,
							},
						},
						legend : { //地图上面的点
							orient : 'vertical',
							right : '70',
							data : [ '福建' ]
						},
						tooltip : { //提示框组件。
							trigger : 'item', //数据项图形触发，主要在散点图，饼图等无类目轴的图表中使用。
							formatter : '{b}: {c}',
							textStyle : {
								fontSize : '24px'
							}
						},
						visualMap : {
							min : minimum,
							max : maximum,
							text : [ '高', '低' ],
							left : '82%',
							realtime : false,
							inRange : {
								color : [ mapchooseColor[0], mapchooseColor[1],
										mapchooseColor[2], mapchooseColor[3],
										mapchooseColor[4], mapchooseColor[5],
										mapchooseColor[6], mapchooseColor[7],
										mapchooseColor[8], mapchooseColor[9],
										mapchooseColor[10] ]
							// color: ['#edfbfb', '#40a9ed', '#3598c1', '#215096', ]
							},
							textStyle : {
								color : '#fff'
							}
						},

						//backgroundColor : 'rgb(7,19,43,1)',
						series : [ {
							type : 'map',
							zoom : 1.1,
							map : 'FuJian',
							// zlevel: 0,
							label : {
								normal : {
									show : true
								}
							},
							itemStyle : {
								emphasis : {
									areaColor : '#fff464'
								}
							},
							data : data
						} ]
					};
					if (option && typeof option === "object") {
				        myChart.setOption(option, true);
				    }
					
				});
				return myChart.getDataURL();
		
	}
	

	
	
	